﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartMathLibrary
{
    /// <summary>
    /// This class provides a perspective matrix for four dimensional vectors.
    /// </summary>
    [Serializable]
    public class PerspectiveMatrix4D
    {
        /// <summary>
        /// The distance for the new perspective.
        /// </summary>
        private double perspective;

        /// <summary>
        /// Initializes a new instance of the <see cref="PerspectiveMatrix4D"/> class.
        /// </summary>
        /// <param name="perspective">The distance for the new perspective illustration.</param>
        public PerspectiveMatrix4D(double perspective)
        {
            this.perspective = perspective;
        }

        /// <summary>
        /// Gets or sets the distance for the new perspective illustration.
        /// </summary>
        /// <value>The distance for the new perspective illustration.</value>
        public double Perspective
        {
            get { return perspective; }
            set { perspective = value; }
        }

        /// <summary>
        /// Gets the perspective matrix for the transformation.
        /// </summary>
        /// <returns>The perspective matrix for the transformation.</returns>
        public Matrix GetPerspectiveMatrix()
        {
            double[,] matrixData = new double[4,4];

            matrixData[0, 0] = 1;
            matrixData[0, 1] = 0;
            matrixData[0, 2] = 0;
            matrixData[0, 3] = 0;

            matrixData[1, 0] = 0;
            matrixData[1, 1] = 1;
            matrixData[1, 2] = 0;
            matrixData[1, 3] = 0;

            matrixData[2, 0] = 0;
            matrixData[2, 1] = 0;
            matrixData[2, 2] = 1;
            matrixData[2, 3] = 0;

            matrixData[3, 0] = 0;
            matrixData[3, 1] = 0;
            matrixData[3, 2] = 1 / this.perspective;
            matrixData[3, 3] = 0;

            return new Matrix(matrixData);
        }
    }
}